package org.devf.fork.imsimulator.model;

import org.devf.fork.imsimulator.socket.dto.BasePackets;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * CurChatCache related
 *
 * @author wanghuafu
 * @since 0.1 2023/9/13
 */
public class CurChatModel {

    private Long sessionId;

    /**
     * 目标好友
     */
    private UserModel destUser;
    /**
     * chat历史消息
     */
    private final List<BasePackets> historyList = new ArrayList<>(50);

    /**
     * 利用MAP用于快速定位消息位置
     * KEY packageId
     * VALUE historyList 的下标
     */
    private final Map<String,Integer> packetsPosition = new HashMap<>();

    /**
     * 将消息添加到容器尾部
     * @param packets 消息包
     */
    public void addPacketsTail(BasePackets packets){
        packetsPosition.put(packets.getPackageId(),historyList.size());
        historyList.add(packets);
    }



    public Long getSessionId() {
        return sessionId;
    }

    public void setSessionId(Long sessionId) {
        this.sessionId = sessionId;
    }

    public UserModel getDestUser() {
        return destUser;
    }

    public void setDestUser(UserModel destUser) {
        this.destUser = destUser;
    }

    public List<BasePackets> getHistoryList() {
        return historyList;
    }

    public Map<String, Integer> getPacketsPosition() {
        return packetsPosition;
    }
}
